import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import redis.clients.jedis.JedisCluster;

import java.io.IOException;
import java.util.Date;
import java.util.logging.*;

/**
 * Created by wchen on 2017/7/15.
 */
public class CacheTest {


    @Test
    public void aa() throws IOException {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
        JedisCluster jedisCluster =  (JedisCluster) applicationContext.getBean("redisClient");
        jedisCluster.del("TT");
        System.out.println(jedisCluster.rpush("TT", "TOKEN1"));
        System.out.println(jedisCluster.set("TOKEN1", "TT"));
/*        jedisCluster.rpush("TT", "TOKEN2");
        jedisCluster.rpush("TT","TOKEN3");
        jedisCluster.rpush("TT", "TOKEN4");*/
        System.out.println(jedisCluster.llen("TT"));
        System.out.println(jedisCluster.lrange("TT", 0, -1));
        System.out.println(jedisCluster.get("TOKEN1"));
        jedisCluster.del(jedisCluster.lpop("TT"));
        System.out.println(jedisCluster.lrange("TT", 0, -1));
        System.out.println(jedisCluster.exists("TOKEN1"));
        System.out.println(jedisCluster.get("TOKEN1"));
        jedisCluster.lrem("TT",0,"TOKEN3");
        System.out.println(jedisCluster.lrange("TT", 0, -1));
        jedisCluster.close();

        
    }
    @Test
    public void bb(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
        JedisCluster jedisCluster =  (JedisCluster) applicationContext.getBean("redisClient");
        System.out.println(jedisCluster.lindex("admin",1));
    }

    @Test
    public void cc(){
        String jwt  = "eyJhbGciOiJIUzI1NiIsImNhbGciOiJERUYifQ.eNpEjksLgzAQhP_LnpOSqCHorVAPQl9YeipF8hLSWhWjUCj97109VPay8-3MsB-Yghuq4ry1dnAhQAY8khuGw4FAmDQSZV--RbVYvYWM48V0vYPsBuVpn1fXS16iYdm3u0NxhDuBtmsr9-794DAyDpMjgBLTgnEpmJSMgFfjH0QzcK3SzRqYO5rOPFfyGD2-5FIWq1homqjU0kTWMdUqMpRrKaTS3ChRw_cHAAD__w.8M-qg_URWOcfPMGwud_0ZOVKqEps9XXhbk9lEcef0sM";
        String JWT1 = "eyJhbGciOiJIUzI1NiIsImNhbGciOiJERUYifQ.eNpEjksLgzAQhP_LnpOSqCHorVAPQl9YeipF8hLSWhWjUCj97109VPay8-3MsB-Yghuq4ry1dnAhQAY8khuGw4FAmDQSZV--RbVYvYWM48V0vYPsBuVpn1fXS16iYdm3u0NxhDuBtmsr9-794DAyDpMjgBLTgnEpmJSMgFfjH0QzcK3SzRqYO5rOPFfyGD2-5FIWq1homqjU0kTWMdUqMpRrKaTS3ChRw_cHAAD__w.8M-qg_URWOcfPMGwud_0ZOVKqEps9XXhbk9lEcef0sM";
        System.out.println(jwt.equals(JWT1));;
    }

    @Test
    public void dd() throws IOException {
        Logger log = Logger.getLogger("tesglog");
        log.setLevel(Level.ALL);
        FileHandler fileHandler = new FileHandler("testlog.log");
        fileHandler.setLevel(Level.ALL);
        fileHandler.setFormatter(new LogFormatter());
        log.addHandler(fileHandler);
        log.info("This is test java util log");
    }

    class LogFormatter extends Formatter {
        @Override
        public String format(LogRecord record) {
            long start = System.currentTimeMillis();
            long end = System.currentTimeMillis();
            System.out.println(end - start + "ms**************************************************************************************");
            Date date = new Date();
            String sDate = date.toString();
            return "[" + sDate + "]" + "[" + record.getLevel() + "]"
                    + record.getClass() + " "+ record.getMessage() + "\n";
        }

    }


}
